;; Macros and their associated Command mappings from object value symbols to side-effects
;;
;; Copyright 2011:
;; James McDermott <jamesmichaelmcdermott@gmail.com>
;; Mark Wagy <mark.wagy@gmail.com>
;;
;; This file is part of p-gen, a p-systems and evolutionary system
;; written in Clojure.
;;
;; p-gen is licensed under GNU GPL v3.
;;
;; http://code.google.com/p/p-gen/



;;;;;;;;;; MACROS

(defmacro init-turtle
  "Macro to init a turtle drawing session."
  []
  `(list 
    (def t (new Turtle))))


(defmacro post-turtle
  "Macro to do post-work on turtle drawing session."
  []
  `(list (. Turtle (draw t 500 500))))


(defmacro t-move
  [turtle dist]
  `(list (. ~turtle move ~dist)))


(defmacro t-turn
  [turtle angle]
  `(list (. ~turtle turn ~angle)))


(defmacro t-red
  [turtle]
  `(list (. ~turtle setColor 1.0 0.0 0.0)))


(defmacro t-black
  [turtle]
  `(list (. ~turtle setColor 0.0 0.0 0.0)))


(defmacro t-green
  [turtle]
  `(list (. ~turtle setColor 0.1 1.0 0.2)))


(defmacro t-gray
  [turtle]
  `(list (. ~turtle setColor 0.7 0.7 0.7)))


(defmacro ts-push [turtle-stack]
  `(list (. ~turtle-stack push)))


(defmacro ts-pop [turtle-stack]
  `(list (. ~turtle-stack pop)))


;;;;;;;;;; MAPS

(def valmap-basic-turtle
     {
      'F `(. t move 10)
      '+ `(. t turn (. Math toRadians 21.5)),
      '- `(. t turn (. Math toRadians -21.5)),
      'push `(. t push),
      'pop `(. t pop)
      })


(def valmap-extended-turtle
     (merge
      valmap-basic-turtle
      {
       'X `(. t move 8),
       'A `(. t move 4),
       '+1 `(. t turn 7.6),
       '-1 `(. t turn -7.6)
       }))


(def valmap-basic-color
     {
      'RED `(. t setColor 0.9 0.22 0.17)
      'BLACK `(. t setColor 0.0 0.0 0.0)
      'GRAY `(. t setColor 0.4 0.4 0.4)
      'GREEN `(. t setColor 0.1 1.0 0.1)
      'ORANGE `(. t setColor 1.0 0.65 0.0)
      nil `(t-black t),
      })


(def valmap-turtle-with-color
     (merge
      valmap-extended-turtle
      valmap-basic-color))


(def valmap-test
     {
      'a `(. t move 50),
      'b `(. t turn (. Math toRadians 41.5)),
      'c `(. t turn (. Math toRadians -41.5)),
      'd `(. t move 10),
      nil `(. t move 0)
      })
